<?php

class Default_Model_DbTable_User extends Zend_Db_Table_Abstract
{
    protected $_name    = 'spagooy_user';
	protected $_primary = 'spagooy_user_id';
	
	
	public function activateUser($data, $userId){
			try {
				$where = $this->getAdapter()->quoteInto('spagooy_user_id = ?',$userId);
				$this->update($data,$where);
			} catch(Exception $e) {
				Zend_Registry::get('errLog')->err('Activate user error: ' . $e);
				throw new Exception('ActivateUser error: ' . $e);
			}
			
			return true;

	}
	
	public function usernameExists($username){
		try {
			$query = $this->select();
			$query->from(array('spagooy_user'), array(
				'spagooy_user_id'
			));
			$query->where('spagooy_user_username = ?', $username);
			$user = $this->fetchAll($query);
			return count($user);

		} catch (Exception $e) {
			Zend_Registry::get('errLog')->err('usernameExists error: ' . $e);
			throw new Exception('usernameExists error: ' . $e);			
		}
	}
	
	public function emailExists($email){
		try {
			$query = $this->select();
			$query->from(array('spagooy_user'), array(
				'spagooy_user_id'
			));
			$query->where('spagooy_user_email = ?', $email);
			$user = $this->fetchAll($query);
			return count($user);

		} catch (Exception $e) {
			Zend_Registry::get('errLog')->err('emailExists error: ' . $e);
			throw new Exception('emailExists error: ' . $e);			
		}
	}
	
	public function numberOfUsers()
	{
		try
		{
			$query = $this->select();
			$query->from(array('spagooy_user'), array('spagooy_user_id'));
			$users = $this->fetchAll($query);
			return count($users);	
		}
		catch(Exception $e)
		{
			Zend_Registry::get('errLog')->err('numberOfUsers error: ' . $e);
			throw new Exception('numberOfUsers error: ' . $e);						
		}
	}
}
